<?php
/**
 * this file is the front controller for the system
 * all requests are routed through this class
 * 
 * @package System
 * @subpackage System_Controller
 * @author Mark Henderson
 */
class System_Controller_Front{
    /**
     * The instance of the FrontController object. (Needed for singleton behavior.) 
     *
     * @var System_Registry The System_Registry object.
     * @static
     * @access private
     */
    private static $_instance = false;
    
    /**
     * holds the current token to be used for all forms during this page load
     * 
     * @var String
     * @static
     * @access private
     */
    private static $_request_token;
    
    /**
     * class constructor set to private
     *
     * @access private
     * @return null
     */
    private function __construct(){}
    
    /**
     * returns an instance of the front controller class
     *
     * @access public
     * @static
     * @return object, instance of this class
     */
    public static function getInstance(){
        if(!self::$_instance) {
            self::$_instance = new self();
        }
        
        return self::$_instance;
    }
    
    /**
     * this method sets the initial session state
     *
     * @access public
     * @return object, instance of this class
     */
    public function setSession(){
        if(!isset($_SESSION['user'])){
            $session = new System_Session_Controller;
            $session->guest();
        }
        
        return $this;
    }
    
    
    public function dispatch(){
        try{
            echo System_Request_Call::url();
        } catch (Exception $e) {
            /**
             * TODO: flesh this section out
             * add proper error page handeling and logging
             */
            echo $e->getMessage();
            System_Request_Command_Abstract::setResponseStatus(401);
        }
    }    
}